import urllib
class MyVideo:
    def __init__(self,url):
        self.headers={'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}; 
        self.url=url;
        self.nUrl='';
        self.files=[];
        self.sus=[];
        self.plays=[];
    def __del__(self):
        self.url='';
    def setName(self,name):
        self.name=name
    def setNUrl(self,nurl):
        self.nUrl=nurl
    def addfile(self,filepath):
        self.files.append(filepath);
    def addSu(self,su):
        self.sus.append(su);
    def addplayer(self,player):
        self.plays.append(player);
    def saveFile(self,name):
        f = file(name,'w')
        f.write('#URL:'+self.url+'\n')
        f.write('#NEXT:'+self.nUrl+'\n')
        for item in self.plays:
            f.write(item+'\n')
        f.close()
    def download(self):
        for k,v in enumerate(self.plays):
            count = len(self.plays)
            print '>>downloading Block %.2d of %.2d' % (k+1,count)
            urllib.urlretrieve(v,'z%.2d.rmvb' % (k+1))
            print '  downloaded Block %.2d completely' % (k+1)
    def printFile(self):
        for item in self.files:
            print 'file='+item
    def printSu(self):
        for item in self.sus:
            print 'su='+item
    def printPlay(self):
        for item in self.plays:
            print 'play='+item

